import { mergeConfig } from 'vite';
import baseConfig from './vite.config.base';
import configCompressPlugin from './plugin/compress';
import configVisualizerPlugin from './plugin/visualizer';
export default mergeConfig(
  {
    mode: 'production',
    plugins: [configCompressPlugin('gzip'), configVisualizerPlugin()],
    build: {
      rollupOptions: {
        output: {
          assetFileNames: (assetInfo) => {
            if (assetInfo.name.endsWith('.css')) {
              return 'static/css/[name]-[hash].[ext]';
            }
            if (
              ['png', 'jpg', 'svg', 'PNG'].some((ext) =>
                assetInfo.name.endsWith(ext)
              )
            ) {
              return 'static/img/[name]-[hash].[ext]';
            }
            if (
              ['ttf', 'woff', 'woff2'].some((ext) =>
                assetInfo.name.endsWith(ext)
              )
            ) {
              return 'static/fonts/[name]-[hash].[ext]';
            }
            return 'static/css/[name]-[hash].[ext]';
          },
        },
      },
      terserOptions: {
        compress: {
          drop_console: false,
          drop_debugger: true,
          pure_funcs: ['console.log'],
        },
        format: {
          /** 删除注释 */
          comments: false,
        },
      },
      minify: 'terser',
      chunkSizeWarningLimit: 2000,
      assetsDir: 'static',
    },
  },
  baseConfig
);
